using System;
using System.Collections; 

namespace Parseq.Core
{
    public abstract class ListParser : BaseParser, IList
    {
        private ArrayList list;
		public ListParser(object[] list) {
            this.list = new ArrayList(list);
        }
        public int Count
        {
            get { return this.list.Count; }
        }

        public bool IsFixedSize
        {
            get { return this.list.IsFixedSize; }
        }

        public bool IsReadOnly
        {
            get { return this.list.IsReadOnly; }
        }

        public bool IsSynchronized
        {
            get { return this.list.IsSynchronized; }
        }

        public object SyncRoot
        {
            get { return this.list.SyncRoot; }
        }

        public object this[int index]
        {
            get { return this.list[index]; }
            set { this.list[index] = value; }
        }

        public int Add(object parser)
        {
            return this.list.Add(parser); 
        }

        public void Clear()
        {
            this.list.Clear(); 
        }

        public bool Contains(object o)
        {
            return this.list.Contains(o); 
        }

        public void CopyTo(Array ary, int index)
        {
            this.list.CopyTo(ary, index); 
        }

        public IEnumerator GetEnumerator()
        {
            return this.list.GetEnumerator(); 
        }

        public int IndexOf(object o)
        {
            return this.list.IndexOf(o);
        }

        public void Insert(int index, object o)
        {
            this.list.Insert(index, o); 
        }

        public void Remove(object o)
        {
            this.list.Remove(o); 
        }

        public void RemoveAt(int i)
        {
            this.list.RemoveAt(i); 
        }

        public void Prepend(BaseParser alternative)
        {
            this.list.Insert(0, alternative);
        }

		public Array ToArray(Type type) {
			Array ary = Array.CreateInstance(type, this.list.Count);
			for (int i = 0; i < this.list.Count; ++i) {
				ary.SetValue(this.list[i], i); 
			}
			return ary; 
		}
		
		public Array ToArray() {
			return this.ToArray(typeof(object)); 			
		}
		
    }
}

